package com.aerozhonghuan.archive.controller;

import com.aerozhonghuan.archive.service.EmergencyRollbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/emergency-rollback")
public class EmergencyRollbackController {

    private final EmergencyRollbackService emergencyRollbackService;

    @Autowired
    public EmergencyRollbackController(EmergencyRollbackService emergencyRollbackService) {
        this.emergencyRollbackService = emergencyRollbackService;
    }

    /**
     * 紧急回迁接口
     *
     * @param configId  迁移配置记录ID
     * @param startTime 紧急回迁起始时间，格式："yyyy-MM-dd HH:mm:ss"
     * @param endTime   紧急回迁结束时间，格式："yyyy-MM-dd HH:mm:ss"
     * @param batchSize 每批次处理的记录数
     * @return 回迁操作结果摘要
     */
    @PostMapping("/execute")
    public String executeEmergencyRollback(
            @RequestParam("configId") Long configId,
            @RequestParam("startTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
            @RequestParam("endTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime,
            @RequestParam("batchSize") int batchSize) {
        return emergencyRollbackService.executeEmergencyRollbackByConfigId(configId, startTime, endTime, batchSize);
    }
}
